Easy to Create, Easy to Change - Easy to use!

Function::Internal

Sum Of

sum of RELATIONSHIP column sum of TABLENAME column Syntax: sum of TABLENAME|RELATIONSHIP [ named "UNIQUE RELATIONSHIP NAME" ] [ with {selection criteria} ] FIELDNAME

The sum of operator sum the FIELDNAME across all records in a related table match the specified selection criteria. The result can appear as a list item in the detail area of a report or as a statistic in the summary area at the end of a report.

There's an important difference between the conditional statistical operator sum and the relational statistical operator sum of. sum sums up the FIELDNAME  of records that satisfy a specified condition among the records being processed. sum of sums the FIELDNAME queried  of matching records related to the records being processed by the script.


Parameters


TABLENAME

You can use Count of directly on a table without a predefined Relationship. Just remember that if there is a Relationship defined that doesn't have an alternative relationship name, this relationship will be named the same and the table and be used. 

RELATIONSHIP

If you use a relationship (alternative name) then the count of will be automatically restricted by the relational restriction. Read under TABLENAME for functionality when using Relationships without alternative relational name.

NAMED "Unique Relationship Name"
You can define an ad hoc named relationship directly in the Count Of function. If you do this you will possibly achieve two things. 1) You will insure against DataEase using a pre-defined relationship with the same name as the table. 2) You can re-use it again in the same script i.e. on a Sum Of etc.
WITH {selection criteria}
With the WITH statement you define the relational restriction of the function. Ex. MyCustomerNR=CustomerNR and MyDate>current date.
FIELDNAME
Name of the Data Column/Field that is being summed up ex. InvoiceLineSum, NumberComplaints, InvoiceTotal

Returns/Result


Numeric Value The sum of FIELDNAME that fit the relational restriction. If no Relational restriction the sum of FIELDNAME in the entire table.

Examples


Example 1

In a field derivation.Simplest type. We have two tables. ThisTable and MyCustomers. We have no relationships defined.

sum of MyCustomers TotalInvoiced

This will return the sum of what I have invoiced all my customers.

Example 2

We have two tables.CustomerType and MyCustomers. We have a relationship between them that connect CustomerType and MyCustomers on customer type.There is no Unique Alternative Name for the Relationship. I have 300 records in MyCustomer and 45 of type Good Credit. As they all buy a fixed service product that cost $10 i will have invoiced them $450.

My active record in CustomerType is the Good Credit record.

sum of MyCustomers TotalInvoiced

This will return the number $450 as I am now using the relationship instead of the table.

sum of MyCustomers named "AllRecords" 

This will return the number $3000 as I have now defined a unique relationship with no restriction and I will get the total invoiced across the table..

Example 3

sum of MyCustomers named "NewRel" with RegistrationDate=current date TotalInvoiced

This will return the total invoiced today

Example 4

for MEMBERS ;

list records

LAST NAME in order ;

sum of RESERVATIONS TOTAL DUE .

end

This script tells DataEase: (1) Process all the MEMBERS records and list each member's LAST NAME in alphabetical order, (2) for each MEMBERS record processed, find all the related records in the RESERVATIONS table (those that have the same MEMBERID), and (3) list the sum of the TOTAL DUE field for the set of RESERVATIONS records that match the current MEMBERS record.

The output from this script might look as follows:

Last Name

Sum of Reservations

Total Due

Adams

$3000.00

Albert

$4760.00

Anders

$4420.00

Andersen

$2100.00

Anderson

$4320.00

Archer...

$4796.00...

If you want to include the sum of this whole group of reservations, change the fourth line of the query to read:

 sum of RESERVATIONS TOTAL DUE : item sum .

Note: There's an important difference between the statistical operator sum and the relational statistical operator sum of. sum returns the total of the values in the specified field among the records being processed. sum of returns the total of the values in the specified field among the records related to the records being processed.


Reference

sum of

Type

Relational Statistical Operator

Purpose

The sum of operator adds the values in a specified field in all matching records in a related table. The result can appear as a list item in the detail area of a report or as a statistic in the summary area at the end of each group or at the end of the report.

Syntax

sum of TABLENAME|RELATIONSHIP

 [named "UNIQUE RELATIONSHIP NAME" ]

 [with ( selection criteria) ] FIELDNAME ; | .

Returns

A numeric value.

Example

for MEMBERS ;

list records

LAST NAME in order ;

sum of RESERVATIONS TOTAL DUE .

end

 

This script tells DataEase: (1) Process all the MEMBERS records and list each member's LAST NAME in alphabetical order, (2) for each MEMBERS record processed, find all the related records in the RESERVATIONS table (those that have the same MEMBERID), and (3) list the sum of the TOTAL DUE field for the set of RESERVATIONS records that match the current MEMBERS record.

The output from this script might look as follows:

 

 

Last Name

Sum of Reservations

 

Total Due

Adams

$3000.00

Albert

$4760.00

Anders

$4420.00

Andersen

$2100.00

Anderson

$4320.00

Archer...

$4796.00...

 

If you want to include the sum of this whole group of reservations, change the fourth line of the query to read:

 

 sum of RESERVATIONS TOTAL DUE : item sum .

 

Note: There's an important difference between the statistical operator sum and the relational statistical operator sum of. sum returns the total of the values in the specified field among the records being processed. sum of returns the total of the values in the specified field among the records related to the records being processed.

See Also


Count Of Highest Of Lowest Of Mean Of

On the forum about Sum Of

Sum of & Sum

I am a 'Returnee' to Dataease.  I used to develop in DE 4.53 but have since lost most of my skills.  I am trying to re-learn and I am having a problem with a dbase I am developing.  The problem is this; I have 2 tables both related.&nbs...

Product: Dataease [{8}]FIVE. Written by Paul Crowther 31/07/13 at 15:06:44

Re:Sum of

Forget about statistical fields and all that stuff.The big secret in DE is using virtual fields that is part of the "table". These can be references like any other field/column.the function to use is: sum ofsum of is a relation...

Product: Dataease [{8}]FIVE. Written by DataEase Tech Sup 31/07/13 at 16:06:46

Sum of calculations

In 5.53 there was a function that allowed you to calculate the total sum of a field by using variables. In DE8 this will not function, it will accept the script provided the "with" is removed and in doing so removes the variables. Is there an alternat...

Product: Dataease [{8}]FIVE. Written by 07/12/13 at 11:45:56

Re:Sum of calculations

Download Sample I think you now are falling in the trap of thinking everything was better in DFD… ;-). You have never been able to use with stateme...

Product: Dataease [{8}]FIVE. Written by DataEase 07/12/13 at 13:11:59

Sum of rows in the row

Hi there,I have two tables, the head (order_head) and the related rows (order_rows) representing orders from customers and containing also the costs to manufacture the products and manage the order. Much of the costs are directly related t...

Product: Dataease [{8}]FIVE. Written by George Washington 17/01/17 at 08:31:26

Re:Sum of rows in the row

I've got myself an answer: I need to create a relationship on order_rows table with itself....

Product: Dataease [{8}]FIVE. Written by George Washington 17/01/17 at 10:41:22

On the blog about Sum Of